All right.
So now that we have our teleporter put together, let's do some scripting.
Let's make it so that when somebody steps on that green pad, they're pad A, they are teleported up
into this box, and the floor of that box is pad B, So we need to remember that pad A to pad B, Let's
go to the teleporter up here on the top level of the model and then add a script.
Here we go.
And let's call the script teleport
and we'll get rid of the print statement.
We need a couple of variables.
We'll do pad A, of course, and that's where the touch events are going to happen.
So we'll say, Script dot Parent, That's the teleporter.
We need to go down to the teleporter, a model and in the model we are going to get pad A run, do the
same for pad B, right?
So this is our destination.
We're not going to have a touched event on it.
We're going to go there.
So I still need it.
Script dot parent Teleporter B dot pad B Now we need a function local function.
We'll call this trans locate and other parts going to get passed in.
Why is that?
Well, our pad, a touched event is going to be connected to trans locate.
There we go.
Get rid of those two extra parentheses.
So when we touch pad A, this is going to be called and it's going and this is going to be like a foot
or something, right?
Because this is a typical touch event.
So the part that touched your pad A is going to get passed in to translocate.
We're going to hope it's a foot.
So we're going to look for the humanoid root part.
Humanoid root part is part of a character.
It's the part that holds the position and orientation of the character.
So if the other parts of the foot, the parent will be the character, then we'll do a fine first child
of humanoid root part.
And if it is a character of some type, we will have the humanoid part.
So we're going to do an EF just in case there isn't a tree or a ball or something like that that hit
the pad.
Now a zombie could theoretically touch that pad, eh?
So we want to only teleport character or players, not characters, not just characters, but playing
characters, right?
So we need a player.
How do we get a player?
We get a player from the player service.
If we look down here, players, that's the player service.
How do we get a reference to that?
Well, we can do local.
I'm going to call it players.
Hopefully that's not too close.
It'll mess you up.
We'll say game, get service players.
That is a variable to that and that keeps track of our players.
So if I do player's colon, get player from character while I have a character, if I have a humanoid
root part, it just might not be a player.
But let's check, we'll do other part parent that would be that would be the character if the player
got returned.
We know it's a player.
If it did get returned, we can get the humanoid root part C frame, which holds the numbers for the
position in the orientation of the character.
We're going to create a new C frame using Pad B's position, right?
But we're not going to worry about orientation.
We're going to let it have the default orientation.
So the character is going to go into our box and they're going to be facing down the Z axis.
That is the default position that you would be in if you did not give an orientation to your C frame.
But we will do that later, not today.
But what we also want to do is make sure we move our C frame our character up a little bit so we don't
get put right in the middle of the floor.
And we can do that by using a vector three at to do vector three new zero on the x three studs, hi
zero on the Y.
So essentially we're moving our C frame up three studs.
So that's where our character is going to end up in the box.
Pretty cool.
Let's go ahead and try it.
And where's our teleporter?
There it is.
Boom!
We're in a box.
Let's check for errors.
Output.
No errors.
All right.
I will continue this in the next video.